home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / xvisrc.zip / PTRFUNC.C < prev    next >
C/C++ Source or Header  |  1992-07-28  |  3KB  |  118 lines

  1. /* Copyright (c) 1990,1991,1992 Chris and John Downey */
  2. #ifndef lint
  3. static char *sccsid = "@(#)ptrfunc.c    2.2 (Chris & John Downey) 8/28/92";
  4. #endif
  5.  
  6. /***
  7.  
  8. * program name:
  9.     xvi
  10. * function:
  11.     PD version of UNIX "vi" editor, with extensions.
  12. * module name:
  13.     ptrfunc.c
  14. * module function:
  15.     Primitive functions on "Posn"s.
  16. * history:
  17.     STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  18.     Originally by Tim Thompson (twitch!tjt)
  19.     Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  20.     Heavily modified by Chris & John Downey
  21.  
  22. ***/
  23.  
  24. #include "xvi.h"
  25.  
  26. /*
  27.  * The routines in this file attempt to imitate many of the operations
  28.  * that used to be performed on simple character pointers and are now
  29.  * performed on Posn's. This makes it easier to modify other sections
  30.  * of the code. Think of a Posn as representing a position in the file.
  31.  * Posns can be incremented, decremented, compared, etc. through the
  32.  * functions implemented here.
  33.  *
  34.  * Note that some functions are now implemented as macros, in ptrfunc.h.
  35.  */
  36.  
  37. /*
  38.  * inc(p)
  39.  *
  40.  * Increment the line pointer 'p' crossing line boundaries as
  41.  * necessary. Return mv_CHLINE when crossing a line, mv_NOMOVE when at
  42.  * end of file, mv_SAMELINE otherwise.
  43.  */
  44. enum mvtype
  45. inc(lp)
  46. register Posn    *lp;
  47. {
  48.     register char *p;
  49.  
  50.     p = &(lp->p_line->l_text[lp->p_index]);
  51.  
  52.     if (*p != '\0') {            /* still within line */
  53.     lp->p_index++;
  54.     return((p[1] != '\0') ? mv_SAMELINE : mv_EOL);
  55.     }
  56.  
  57.     if (!is_lastline(lp->p_line->l_next)) {
  58.     lp->p_index = 0;
  59.     lp->p_line = lp->p_line->l_next;
  60.     return(mv_CHLINE);
  61.     }
  62.  
  63.     return(mv_NOMOVE);
  64. }
  65.  
  66. /*
  67.  * dec(p)
  68.  *
  69.  * Decrement the line pointer 'p' crossing line boundaries as
  70.  * necessary. Return mv_CHLINE when crossing a line, mv_NOMOVE when at
  71.  * start of file, mv_SAMELINE otherwise.
  72.  */
  73. enum mvtype
  74. dec(lp)
  75. register Posn    *lp;
  76. {
  77.     if (lp->p_index > 0) {            /* still within line */
  78.     lp->p_index--;
  79.     return(mv_SAMELINE);
  80.     }
  81.  
  82.     if (!is_line0(lp->p_line->l_prev)) {
  83.     lp->p_line = lp->p_line->l_prev;
  84.     lp->p_index = strlen(lp->p_line->l_text);
  85.     return(mv_CHLINE);
  86.     }
  87.  
  88.     return(mv_NOMOVE);                /* at start of file */
  89. }
  90.  
  91. /*
  92.  * pswap(a, b) - swap two position pointers.
  93.  */
  94. void
  95. pswap(a, b)
  96. register Posn    *a, *b;
  97. {
  98.     register Posn    tmp;
  99.  
  100.     tmp = *a;
  101.     *a  = *b;
  102.     *b  = tmp;
  103. }
  104.  
  105. /*
  106.  * Posn comparisons.
  107.  */
  108. bool_t
  109. lt(a, b)
  110. register Posn    *a, *b;
  111. {
  112.     if (a->p_line != b->p_line) {
  113.     return(earlier(a->p_line, b->p_line));
  114.     } else {
  115.     return(a->p_index < b->p_index);
  116.     }
  117. }
  118.